package com.ruoyi.zsyh.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.ZtreeString;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zsyh.mapper.ZsyhServiceTypeMapper;
import com.ruoyi.zsyh.domain.ZsyhServiceType;
import com.ruoyi.zsyh.service.IZsyhServiceTypeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 服务分类Service业务层处理
 * 
 * @author yuexl
 * @date 2022-02-10
 */
@Service
public class ZsyhServiceTypeServiceImpl implements IZsyhServiceTypeService 
{
    @Autowired
    private ZsyhServiceTypeMapper zsyhServiceTypeMapper;

    /**
     * 查询服务分类
     * 
     * @param id 服务分类ID
     * @return 服务分类
     */
    @Override
    public ZsyhServiceType selectZsyhServiceTypeById(String id)
    {
        return zsyhServiceTypeMapper.selectZsyhServiceTypeById(id);
    }

    /**
     * 查询服务分类列表
     * 
     * @param zsyhServiceType 服务分类
     * @return 服务分类
     */
    @Override
    public List<ZsyhServiceType> selectZsyhServiceTypeList(ZsyhServiceType zsyhServiceType)
    {
        return zsyhServiceTypeMapper.selectZsyhServiceTypeList(zsyhServiceType);
    }

    /**
     * 新增服务分类
     * 
     * @param zsyhServiceType 服务分类
     * @return 结果
     */
    @Override
    public int insertZsyhServiceType(ZsyhServiceType zsyhServiceType)
    {
        zsyhServiceType.setCreateTime(DateUtils.getNowDate());
        zsyhServiceType.setId(IdWorker.getId());
        return zsyhServiceTypeMapper.insertZsyhServiceType(zsyhServiceType);
    }

    /**
     * 修改服务分类
     * 
     * @param zsyhServiceType 服务分类
     * @return 结果
     */
    @Override
    public int updateZsyhServiceType(ZsyhServiceType zsyhServiceType)
    {
        zsyhServiceType.setUpdateTime(DateUtils.getNowDate());
        return zsyhServiceTypeMapper.updateZsyhServiceType(zsyhServiceType);
    }

    /**
     * 删除服务分类对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteZsyhServiceTypeByIds(String ids)
    {
        return zsyhServiceTypeMapper.deleteZsyhServiceTypeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除服务分类信息
     * 
     * @param id 服务分类ID
     * @return 结果
     */
    @Override
    public int deleteZsyhServiceTypeById(String id)
    {
        return zsyhServiceTypeMapper.deleteZsyhServiceTypeById(id);
    }

    /**
     * 查询服务分类树列表
     * 
     * @return 所有服务分类信息
     */
    @Override
    public List<ZtreeString> selectZsyhServiceTypeTree()
    {
        List<ZsyhServiceType> zsyhServiceTypeList = zsyhServiceTypeMapper.selectZsyhServiceTypeList(new ZsyhServiceType());
        List<ZtreeString> ztrees = new ArrayList<ZtreeString>();
        for (ZsyhServiceType zsyhServiceType : zsyhServiceTypeList)
        {
            ZtreeString ztree = new ZtreeString();
            ztree.setId(zsyhServiceType.getId());
            ztree.setpId(zsyhServiceType.getParentId());
            ztree.setName(zsyhServiceType.getServiceName());
            ztree.setTitle(zsyhServiceType.getServiceName());
            ztrees.add(ztree);
        }
        return ztrees;
    }

    /**
     * 查询服务分类树列表
     *
     * @return 所有服务分类信息
     */
    @Override
    public List<ZtreeString> selectZsyhServiceTypeTreeSecond()
    {
        List<ZsyhServiceType> zsyhServiceTypeList = zsyhServiceTypeMapper.selectZsyhServiceTypeList(new ZsyhServiceType());
        List<ZtreeString> ztrees = new ArrayList<ZtreeString>();
        for (ZsyhServiceType zsyhServiceType : zsyhServiceTypeList)
        {
            if(!"3".equals(zsyhServiceType.getServiceLevel())){
                ZtreeString ztree = new ZtreeString();
                ztree.setId(zsyhServiceType.getId());
                ztree.setpId(zsyhServiceType.getParentId());
                ztree.setName(zsyhServiceType.getServiceName());
                ztree.setTitle(zsyhServiceType.getServiceName());
                ztrees.add(ztree);
            }
        }
        return ztrees;
    }
}
